#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int main()
{
    int n, i, p;
    int b = 0;
    int c = 0;
    int arr[100];
    scanf("%d", &n);
    for (i = 0; i < n; i++)
    {
        scanf("%d", &arr[i]);
    }
    int min = arr[0];
    for (i = 0; i < n; i++)
    {
        if (arr[i] < min)
        {
            min = arr[i];
            c = i;
        }
    }
    p = arr[0];
    arr[c] = p;
    arr[0] = min;
    int max = arr[0];
    for (i = 0; i < n; i++)
    {
        if (arr[i] > max)
        {

            max = arr[i];
            b = i;
        }
    }
    p = arr[n - 1];
    arr[b] = p;
    arr[n - 1] = max;
    for (i = 0; i < n; i++)
    {
        printf("%d ", arr[i]);
    }
    return 0;
}